package com.exm.collectcodenew.kafka.producer.customSerializer;

import com.alibaba.fastjson.JSON;
import org.apache.kafka.common.serialization.Serializer;

import java.nio.charset.StandardCharsets;
import java.util.Map;
public class UserSerializer implements Serializer<User> {
    @Override
    public void configure(Map configs, boolean isKey) {
    }
    @Override
    public byte[] serialize(String topic, User data) {
        if (data == null){
           System.out.println("Null received at serializing");
           return null;
        }
        String userStr = JSON.toJSONString(data);
        return userStr.getBytes(StandardCharsets.UTF_8);
    }
    @Override
    public void close() {
    }
}
